﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using HelloMinasan.Domain;
using HelloMinasan.Business;
using System.Web.Mvc;
using HelloMinasan.Business.Extend;

namespace HelloMinasan.Web.Song.ViewModels
{
    public class CommentModels
    {
        [Display(Name = "Comment Id")]
        public int CommentId { get; set; }

        [Required]
        [StringLength(300, MinimumLength = 10, ErrorMessage = "Comment must be from 10-300 characters.")]
        [Display(Name = "Comment content")]
        public string CommentContent { get; set; }

        [Display(Name = "Last Update")]
        public DateTime LastUpdate { get; set; }

        //[Display(Name = "Owner Account")]
        //public UserModels OwnerAccount { get; set; }

        [Display(Name = "Song Id")]
        public int SongId { get; set; }
    }

    public class PagingHelper
    {
        private int _currentPageNumber = 1;

        public int PreviousPageNumber
        {
            get
            {
                return CurrentPageNumber - 1;
            }
        }

        public int NextPageNumber
        {
            get
            {
                return CurrentPageNumber + 1;
            }
        }

        public int CurrentPageNumber
        {
            get
            {
                return _currentPageNumber;
            }
            set
            {
                _currentPageNumber = value;
            }
        }
    }

    public class WrapCommentModels
    {
        public WrapCommentModels()
        {
            CurrentComment = new CommentModels();
        }

        public PagingHelper PagingControl { get; set; }

        public IEnumerable<SongComment> Comments
        {
            get
            {
                int totalPageCount;

                //var list = new SongCommentRepository()
                //    .GetSongSommentsBySongId(SongId, out totalPageCount, PagingControl.CurrentPageNumber);
                ISongService songService = DependencyResolver.Current.GetService<ISongService>();
                var list = songService.GetSongSommentsBySongId(SongId, out totalPageCount, PagingControl.CurrentPageNumber);
                var badWords = songService.GetBadWord();

                TotalPageCount = totalPageCount;
                foreach (var itemComment in list)
                {
                    itemComment.CommentContent += " ";
                    //foreach (var itemBadWords in MvcApplication.FilterWords)
                    foreach (var itemBadWords in badWords)
                    {
                        //itemComment.CommentContent = itemComment.CommentContent.Replace(itemBadWords.Words + " ", Resource.Song_BadWords + " ");
                        //itemComment.CommentContent = itemComment.CommentContent.Replace(" " + itemBadWords.Words + " ", " " + Resource.Song_BadWords + " ");
                        itemComment.CommentContent = itemComment.CommentContent.Replace(itemBadWords.Words + " ", "BadWords" + " ");
                        itemComment.CommentContent = itemComment.CommentContent.Replace(" " + itemBadWords.Words + " ", " " + "BadWords" + " ");
                    }
                }
                return list;
            }
        }

        public bool JustPerformBadWordItem { get; set; }

        public int SongId { get; set; }

        public int TotalPageCount
        {
            set;
            get;
        }

        public CommentModels CurrentComment { get; set; }
    }
}